package com.yansl.http.intercepter;

import java.util.Map;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;

import lombok.extern.slf4j.Slf4j;

/**
 * @description: HTTP拦截器
 * @author: yansl.cn
 * @create: 2022-12-18 14:25
 */
@Slf4j
public class DefaultHttpIntercepter implements HttpIntercepter {

    @Override
    public Class getHttpIntercepterClass() {
        return DefaultHttpIntercepter.class;
    }

    @Override
    public HttpHeaders requestHeads(HttpHeaders headers) {
        log.info(" 请求-头 {}", headers);
        return headers;
    }

    @Override
    public String requestUrl(String url) {
        log.info(" 请求-URL {}", url);
        return url;
    }

    @Override
    public boolean requestBefore(HttpMethod httpMethod, String url, Map<String, Object> params) {
        log.info(" 请求-之前 {}，{} , {}", httpMethod, url, params);
        return true;
    }

    @Override
    public String requestAfter(ResponseEntity<String> responseEntity) {
        log.info(" 请求-之后 {}", responseEntity);
        return responseEntity.getBody();
    }
}
